# 仅用于生成 zobrist.py 文件, 可直接运行

import random
from gotypes import Player, Point

def ToPython(player):
    if player is None:
        return 'None'
    if player == Player.black:
        return Player.black
    return Player.white

def GenerateZobrist(filename):
    MAX63 = 0x7fffffffffffffff
    table = {}
    # empty_code = random.randint(0,MAX63)
    for r in range(1,20):
        for c in range(1,20):
            for p in (None, Player.black, Player.white):
                code = random.randint(0, MAX63)
                table[Point(r,c),p] = code

    s = '''# 自动生成, 不可手动更改
from .gotypes import Player, Point

__all__ = ['HashCode', 'EmptyCode']

HashCode = { '''

    s += '\n'
    for (pt, player), hash_code in table.items():
        s += f'\t({pt}, {ToPython(player)}): {hash_code},\n'
    s += '}\n'

    s += f'EmptyCode = {random.randint(0,MAX63)}'

    # print(s)
    with open(filename, 'w') as f:
        f.write(s)

GenerateZobrist('zobrist.py')